<?php
// Copyright (c) 2009, 백괴사전 all rights reserved.
// Distributed under GNU General Public License v3.
// Read LICENSE for more information.

if(defined('MEDIAWIKI')===false) {
	echo '이 파일은 미디어위키 확장 기능 정의 파일이기 때문에 단독으로 실행할 수 없습니다.';
	exit;
}

if(defined('LF')===false)
	define('LF',chr(0x0A));
if(defined('TB')===false)
	define('TB',chr(0x09));

if(defined('UP_EXT_ROOT')==false)
	define('UP_EXT_ROOT',strtr(__FILE__,array('UP.General.UncycloPack.php'=>'')));
if(defined('UP_EXT_WEB_ROOT')===false)
	define('UP_EXT_WEB_ROOT',strtr(substr(__FILE__,strpos(__FILE__,$wgScriptPath)),array('UP.General.UncycloPack.php'=>'')));

include_once UP_EXT_ROOT.'SI.g11n.Encoding.UTF8.php';
include_once UP_EXT_ROOT.'SI.g11n.Language.Korean.php';
include_once UP_EXT_ROOT.'UP.Library.JosaFunctions.php';


$wgExtensionCredits['parserhook'][]=array(
'name'=>'백괴팩',
'version'=>'1.0',
'author'=>'[[백괴사전]]',
'url'=>'http://uncyclopedia.kr/wiki/백괴사전:백괴팩',
'description'=>'백괴팩(UncycloPack)은 [[한국어]] [[백괴사전]]용 확장 기능 패키지입니다. 이 패키지는 다음을 포함합니다: [[Dksemfhdj]], [[Icufjt]], [[글글자자가가_두두_개개씩씩_써써져져요요]], [[로꾸거어]], [[백괴게임:대문|백괴게임]] 로고 링크 변환기, [[씨프트까 안 빠쪄요]], [[종성 내려 쓰기]], [[촛엉 올려 쓱이]], [[백괴사전:큐브|큐브]] 지도, 한국어 조사 처리기(by [[사용자:Peremen|Peremen]])'
);
$wgExtensionFunctions[]='UP_Initializer';


function UP_Initializer() {
	global $wgParser,$wgHooks;
	
	$wgHooks['BeforePageDisplay'][]='UP_LogoLinkHelper_Initialize';
	$wgHooks['LanguageGetMagic'][]='UP_JosaFunction_Magic';
	
	$wgParser->setHook('choseong','UP_ChoseongTrifler');
	$wgParser->setHook('cubemap','UP_CubeMapper');
	$wgParser->setHook('jongseong','UP_JongseongTrifler');
	$wgParser->setHook('ungamemain','UP_LogoLinkHelper');
	$wgParser->setFunctionHook('을를','UP_JosaFunction_EulReul');
	$wgParser->setFunctionHook('이가','UP_JosaFunction_IGa');
	$wgParser->setFunctionHook('이','UP_JosaFunction_I');
	$wgParser->setFunctionHook('은는','UP_JosaFunction_EunNeun');
	$wgParser->setFunctionHook('과와','UP_JosaFunction_GwaWa');
	$wgParser->setFunctionHook('아야','UP_JosaFunction_AYa');
	$wgParser->setFunctionHook('으','UP_JosaFunction_Eu');
	
	return true;
}

/*

Overview : Automated 촛엉 올려 쓱이 processor
Usage : <choseong>'촛엉 올려 쓱이'를 적용할 문장</choseong>

*/
function UP_ChoseongTrifler($upxlRequestStr,$upxlNoOptionsArr,&$upxgWikiParserObj) {
	include_once UP_EXT_ROOT.'UP.Library.ChoseongTrifler.php';
	
	return '<span style="color:#FF0000;">현재 구현중입니다.</span>';
}

/*

Overview : Map implementation for 백괴게임:큐브
Usage : <cubemap block="블럭 문자" cols="열 수" highlight="#강조 색상" rows="행 수" separator="블럭 구분 문자">현재 칸번호</cubemap>

*/
function UP_CubeMapper($upxlBlockNumberStr,$upxlOptionsArr,&$upxgWikiParserObj) {
	$upxlBlockHighlightStr=(isset($upxlOptionsArr['highlight'])===false && empty($upxlOptionsArr['highlight'])===true)?'#FFA500':$upxlOptionsArr['highlight'];
	
	$upxlBlockStr=(isset($upxlOptionsArr['block'])===false && empty($upxlOptionsArr['block'])===true)?'██':$upxlOptionsArr['block'];
	
	$upxlColsInt=(isset($upxlOptionsArr['cols'])===false && empty($upxlOptionsArr['cols'])===true)?16:$upxlOptionsArr['cols'];
	
	$upxlRows1Int=(isset($upxlOptionsArr['rows'])===false && empty($upxlOptionsArr['rows'])===true)?17:$upxlOptionsArr['rows']+1;
	$upxlRows2Int=(isset($upxlOptionsArr['rows'])===false && empty($upxlOptionsArr['rows'])===true)?16:$upxlOptionsArr['rows'];
	
	$upxlSeparatorStr=(isset($upxlOptionsArr['separator'])===false && empty($upxlOptionsArr['separator'])===true)?' ':$upxlOptionsArr['separator'];
	
	$upxlBlockNumberInt=$sixgWikiParserObj->recursiveTagParse($upxlBlockNumberStr);
	settype($upxlBlockNumberInt,'integer');
	
	$upxlTmpArrayArr=array();
	for($upxlLoopIndex1Int=1;$upxlLoopIndex1Int<$upxlRows1Int;$upxlLoopIndex1Int++) {
		$upxlTmpBlocksStr='';
		for($upxlLoopIndex2Int=0;$upxlLoopIndex2Int<$upxlColsInt;$upxlLoopIndex2Int++) {
			if((($upxlRows2Int*$upxlLoopIndex2Int)+$upxlLoopIndex1Int)===$upxlBlockNumberInt)
				$upxlTmpBlocksStr.='<span style="color:'.$upxlBlockHighlightStr.';">'.$upxlBlockStr.'</span>'.$upxlSeparatorStr;
			else
				$upxlTmpBlocksStr.=$upxlBlockStr.$upxlSeparatorStr;
		}
		$upxlTmpArrayArr[16-$upxlLoopIndex1Int]=substr($upxlTmpBlocksStr,0,-1);
	}
	unset($upxlBlockHighlightStr,$upxlBlockStr,$upxlColsInt,$upxlRows1Int,$upxlRows2Int,$upxlSeparatorStr,$upxlLoopIndex1Int,$upxlTmpBlocksStr,$upxlLoopIndex2Int);
	
	return implode('<br />'.LF,array_reverse($upxlTmpArrayArr));
}

/*

Overview : Automated 종성 내려 쓰기 processor
Usage : <jongseong>'종성 내려 쓰기'를 적용할 문장</jongseong>

*/
function UP_JongseongTrifler($upxlRequestStr,$upxlNoOptionsArr,&$upxgWikiParserObj) {
	include_once UP_EXT_ROOT.'UP.Library.JongseongTrifler.php';
	
	return '<span style="color:#FF0000;">현재 구현중입니다.</span>';
}

/*

Overview : Help runLogoLinkChanger()'s complicated logo link modification process
Usage : <ungamemain />

*/
function UP_LogoLinkHelper($upxlNoInputStr,$upxlNoOptionsArr,&$upxgWikiParserObj) {
	$upxlRtnStr=LF;
	$upxlRtnStr.='<script type="text/javascript">'.LF;
	$upxlRtnStr.='//<![CDATA['.LF;
	$upxlRtnStr.=TB.'upfgIsUngameMain=true;'.LF;
	$upxlRtnStr.='//]]>'.LF;
	$upxlRtnStr.='</script>'.LF;
	
	return $upxlRtnStr;
}

/*

Overview : Automated runLogoLinkMutator() insertion
Usage : None

*/
function UP_LogoLinkHelper_Initialize(&$upxgOutputPageObj,&$upxgSkinObj) {
	global $wgScriptPath;
	
	$upxgOutputPageObj->addScript('<script charset="UTF-8" src="'.UP_EXT_WEB_ROOT.'/UP.Helper.LogoLinkMutator.js" type="text/javascript"></script>'.LF);
	
	return true;
}

?>